#!/bin/bash

# Logical Operation

#-- OR Operation '|' -- 
# the pip character is used to represent logical operation "OR"

# * print lines containing either 101 or 102
sed -n '/101\|102/ p' ../sed/test_employee.txt # | symbol is escaped with a back-slash
echo -e '\n'



#-- Exactly M Occurrences '({m})'

# * print lines contains a character from 2 or 3 or 105
sed -n '/[23]\|105/ p' ../sed/test_employee.txt
echo -e '\n'

# * print lines contians any digit
sed -n '/[0-9]/ p' ../sed/test_employee.txt
echo -e '\n'

# * print lines consisting of exactly 5 digits
sed -n '/^[0-9]\{5\}$/ p' ./test_numbers.txt
echo -e '\n'

#-- M to N Occurrences ({m,n})
# a regular expression followd by {m,n} indicates that the preceding item must match at least m times,
# but not more than n times. valid number range is [0,255]

# * print lines consisting of at least 3 but more than 5 digits
sed -n '/^[0-9]\{3,5\}$/ p' ./test_numbers.txt
echo -e '\n'


#-- Word Boundary -- (\b)
# \b is used to match a word boundary. \b matches any character at the beginning (\bxxx) and / or end (xx\b) of a word, thus '\bthe\b' will find 'the' but not 'they'
# '\bthe' will find 'they'

# - match lines containing the whole word 'the'
sed -n '/\bthe\b/ p' ./test_words.txt
echo -e '\n'

# - match lines that starting with 'the' 
sed -n '/\bthe/ p' ./test_words.txt
echo -e '\n'


#-- Back References \n 
# it let you group expresson for further use, n is number 

# - match the line that 'the' repeated twice 
sed -n '/\(the\)\1/ p' ./test_words.txt
echo -e '\n'
